package com.bailanzu.tool;

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class Windows implements Runnable {

/**
* All rights Reserved, Designed By https://gitee.com/es-cape/escape.git
 *
 * @ProjectName:
 * @Package:
 * @ClassName:
        *@param
        *@return
        * @Description: $[description]
        * <p> </p>
 * @Author: escape
        * @Date: 2022/5/11
        * @Version:
*/

    //通过Random类中的nextInt (int n)方法，生成1-3的随机数 1代表剪刀 2代表石头 3代表布
    //应用数学公式代替逻辑公式判断人机对战的输赢
    //1代表剪刀 2代表石头  3代表布
    //（person-computer+3）%3
    //person-computer=0为平局 person-computer=1 人赢了 person-computer=2 人输了
    //person-computer=-1 人输了 person-computer=-2 人赢了
    //  总结：人-电脑 = 0（平）; (人-电脑+3)%3 = 1（人胜）; (人-电脑+3)%3 = 2（电脑胜）
    @Override
    public void run() {

        JFrame jf = new JFrame("石头剪刀布");
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


        JButton btn01 = new JButton("剪刀");
        JButton btn02 = new JButton("石头");
        JButton btn03 = new JButton("布");

        Box hBox01 = Box.createHorizontalBox();
        hBox01.add(btn01);
        hBox01.add(btn02);
        hBox01.add(btn03);


        Box hBox02 = Box.createHorizontalBox();
        JTextField jtf1 = new JTextField("结果");
        JTextField jtf2=new JTextField("         ");
        jtf1.setEnabled(false);
        jtf2.setEnabled(false);
        hBox02.add(jtf1);
        hBox02.add(jtf2);

        Box hBox03=Box.createHorizontalBox();
        JTextField jtf3 = new JTextField("赢：");
        JTextField jtf4=new JTextField("  ");
        JTextField jtf5 = new JTextField("平：");
        JTextField jtf6=new JTextField("  ");
        JTextField jtf7 = new JTextField("输：");
        JTextField jtf8=new JTextField("  ");
        jtf3.setEnabled(false);
        jtf4.setEnabled(false);
        jtf5.setEnabled(false);
        jtf6.setEnabled(false);
        jtf7.setEnabled(false);
        jtf8.setEnabled(false);
        hBox03.add(jtf3);
        hBox03.add(jtf4);
        hBox03.add(jtf5);
        hBox03.add(jtf6);
        hBox03.add(jtf7);
        hBox03.add(jtf8);

        Box vBox = Box.createVerticalBox();
        vBox.add(hBox01);
        vBox.add(hBox02);
        vBox.add(hBox03);

        jf.setContentPane(vBox);
        jf.pack();
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);
///---------------------------------------------------------------------------//



        btn01.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //启动对局线程
                ToneScissorClothImpl standard = new ToneScissorClothImpl();
                Random random = new Random();
                int computer = random.nextInt(3)+1;
                standard.gamestander(2,computer);
                jtf2.setText(ToneScissorClothImpl.result);
                jtf4.setText(String.valueOf(Result.win));
                jtf6.setText(String.valueOf(Result.fair));
                jtf8.setText(String.valueOf(Result.lose));
            }
        });
        btn02.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //启动对局线程
                ToneScissorClothImpl standard = new ToneScissorClothImpl();
                Random random = new Random();
                int computer = random.nextInt(3);
                standard.gamestander(1,computer);
                jtf2.setText(ToneScissorClothImpl.result);
                jtf4.setText(String.valueOf(Result.win));
                jtf6.setText(String.valueOf(Result.fair));
                jtf8.setText(String.valueOf(Result.lose));

            }
        });
        btn03.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //启动对局线程
                ToneScissorClothImpl standard = new ToneScissorClothImpl();
                Random random = new Random();
                int computer = random.nextInt(3);
                standard.gamestander(3,computer);
                jtf2.setText(ToneScissorClothImpl.result);
                jtf4.setText(String.valueOf(Result.win));
                jtf6.setText(String.valueOf(Result.fair));
                jtf8.setText(String.valueOf(Result.lose));

            }
        });
    }
}
